import React from 'react'
import { Layout,Image} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import "./tr.css"
import {useSelector,useDispatch,connect} from 'react-redux'
const {Content} = Layout;

const Hotel = () => {

  const hotelList = useSelector(state=> state.hotel.hotelList)
  const valueList = useSelector(state=> state.value.valueList)
  const dispatch = useDispatch()
  const columns = [
    {
      title: '酒店名称',
      key: 'pubName',
      dataIndex: 'pubName',
      valueType: 'text'
    },
    {
      title: '酒店图片',
      key: 'pubImg',
      dataIndex: 'pubImg',
      ellipsis:true,
      hideInSearch:true,
      render:(text,record)=>{
        if((record.pubImg).search(';') == -1){
          return(
            <Image.PreviewGroup>
              <Image width={30} height ={30} src={record.pubImg} />
            </Image.PreviewGroup>
          )

        }else{
          return (
            <Image.PreviewGroup>
              {
                (record.pubImg).split(";").map((items, index) =>{
                  return <Image width={30} height ={30} src={items} />

                }
                )
              }
            </Image.PreviewGroup>
            
          )
        }
      }
    },
    {
      title: '营业时间',
      key: 'pubTime',
      dataIndex: 'pubTime',
      valueType: 'text'
    },
    {
      title: '酒店位置',
      key: 'pubAddr',
      dataIndex: 'pubAddr',
      valueType: 'text'
    },
    {
      title: '舒适指数',
      key: 'pubNo',
      dataIndex: 'pubNo',
      valueType: 'text'
    },
    {
      title: '酒店评价',
      key: 'pubTalk',
      dataIndex: 'pubTalk',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '酒店类型',
      key: 'pubType',
      dataIndex: 'pubType',
      valueType: 'text',
      ellipsis:true
    },
    {
      title: '用户评论',
      key: 'upubTalk',
      dataIndex: 'upubTalk',
      valueType: 'text',
      ellipsis:true
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});console.log(valueList)
        }}><Editor ques={hotel} url="http://49.233.107.127:2002/city/hotel"/></div>
        ,  <a onClick={async ()=>{
          console.log(record)
          await fetch(`http://49.233.107.127:2002/city/hotel/${record.pubID}/${record.cityID}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          }
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];
  
    const right = {
      pubTalk:{
        show:false,
        order:2
      },
      pubType:{
        show:false,
        order:2
      },
      upubTalk:{
        show:false,
        order:2
      },
        pubNo:{
          show:false,
          order:2
      }
    }

    const hotel = [
      {name:'cityID',label:'城市id',tooltip:'最长为24位',placeholder:'输入城市id'},
      {name:'pubID',label:'酒店id',tooltip:'最长为24位',placeholder:'请输入酒店id'},
      {name:'pubName',label:'酒店名称',tooltip:'最长为24位',placeholder:'输入酒店名称'},
      {name:'pubImg',label:'酒店图片',placeholder:'上传图片'},
      {name:'pubTime',label:'营业时间',tooltip:'最长为24位',placeholder:'输入营业时间'},
      {name:'pubTalk',label:'酒店介绍',placeholder:'输入酒店介绍'},
      {name:'upubTalk',label:'用户评论',placeholder:'输入用户评论'},
      {name:'pubAddr',label:'酒店位置',placeholder:'请输入酒店位置'},
      {name:'pubNo',label:'酒店等级',placeholder:'输入酒店等级'},
      {name:'pubType',label:'酒店类型',placeholder:'输入酒店类型'}
  ]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          <Table title="酒店推荐管理" columns={columns} right={right} url="http://49.233.107.127:2002/city/hotel" ques={hotel}/>
        </Content>
    )
}

export default connect()(Hotel)
